package com.zzyl.controller.manager;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.dto.AlertRuleQueryDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.AlertRuleVo;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.QueryThingModelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警规则相关接口")
@RequiredArgsConstructor
public class AlertRuleController {
    private static final Logger log = LoggerFactory.getLogger(AlertRuleController.class);
    final AlertRuleService alertRuleService;
    final DeviceService deviceService;


    @ApiOperation(value = "新增报警规则")
    @PostMapping("create")
    public ResponseResult<Void> create(@RequestBody AlertRuleDto alertRuleDto) {
        log.info("新增报警规则:{}", alertRuleDto);
        alertRuleService.createRule(alertRuleDto);
        return ResponseResult.success();
    }


    @ApiOperation(value = "获取单个告警规则")
    @GetMapping("read/{id}")
    public ResponseResult<AlertRuleVo> read(@PathVariable Long id) {
        log.info("获取单个告警规则:id:{}", id);
        AlertRuleVo alertRuleVo = alertRuleService.readAlertRule(id);
        return ResponseResult.success(alertRuleVo);
    }


    @ApiOperation(value = "更新告警规则")
    @PutMapping("update/{id}")
    public ResponseResult<Void> update(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        log.info("更新告警规则:id:{},alertRuleDto:{}", id, alertRuleDto);
        alertRuleService.updateAlertRule(id, alertRuleDto);
        return ResponseResult.success();
    }


    @ApiOperation(value = "删除告警规则")
    @DeleteMapping("delete/{id}")
    public ResponseResult<Void> delete(@PathVariable Long id) {
        log.info("删除告警规则:id:{}", id);
        alertRuleService.deleteAlertRule(id);
        return ResponseResult.success();
    }


    @ApiOperation(value = "分页获取告警规则列表")
    @GetMapping("get-page")
    public ResponseResult<PageBean<AlertRuleVo>> getPage(AlertRuleQueryDto dto) {
        log.info("分页获取告警规则列表:{}", dto);
        PageBean<AlertRuleVo> page = alertRuleService.getAlertRulePage(dto);
        return ResponseResult.success(page);
    }

    @ApiOperation("启用/禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult<Void> enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用、禁用护理项目:id:{},status:{}", id, status);
        alertRuleService.enableOrDisable(id, status);
        return ResponseResult.success();
    }
}
